package com.factory.simplefactory.pizzastore.order;

import com.factory.simplefactory.pizzastore.pizzapojo.CheesePizza;
import com.factory.simplefactory.pizzastore.pizzapojo.GreekPizza;
import com.factory.simplefactory.pizzastore.pizzapojo.Pizza;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author 薛虎
 * @date 2020/12/17 11:14
 * 简单工厂模式
 */
public class OrderPizza {

    //构造器
    public OrderPizza() {
        Pizza pizza = null;
        String orderType; //订购披萨的类型

        do {
            orderType = getType();
            if (orderType.equals("greek")) {
                pizza = new GreekPizza();
                pizza.setName("希腊披萨");
            } else if (orderType.equals("cheese")) {
                pizza = new CheesePizza();
                pizza.setName("奶酪披萨");
            } else {
                break;
            }

            //输出pizza 制作的过程
            //1.准备原材料
            pizza.prepare();
            //2.烘烤
            pizza.bake();
            //3.切割
            pizza.cut();
            //4.打包
            pizza.box();
        } while (true);

    }


    //写一个方法,可以获取客户希望订购的披萨种类
    private String getType() {
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza 种类:");
            String str = bufferedReader.readLine();
            return str;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

}
